<template>
	<view class="article">
		<ABanner :highLight="num" @sendNum="handleGet" :menuList="['我的帖子']"></ABanner>
		<view v-if="article.params.length>0" class="content">
			<view v-for="(item,index) in article.params" :key="index">
				<ABlogCard :sh="true" @reloadItem="getItem" :item="item"></ABlogCard>
			</view>
		</view>
		<view v-else class="empty_container">
			<u-empty text="暂无发布帖子" mode="data" width="100%" iconSize="60" textSize="32"></u-empty>
		</view>
	</view>
</template>

<script>
	import {
		getMyComment
	} from '@/api/forum.js'
	export default {
		mounted() {
			// 重新获取数据
			uni.$on('reloadlist', () => {
				this.pageParams.pageNum = 1
				this.getList(this.pageParams, false)
			})
			// uni.$on('reloaditem',(item)=>{
			// 	console.log(this.article,'article');
			// })
		},
		onLoad() {
			getMyComment().then(res => {
				this.article.params = res.data.blogList
			})
		},
		onReachBottom() {
			if (this.article.total !== this.article.params.length) {
				this.pageParams.pageNum += 1
				this.getList(this.pageParams)
			}
		},
		data() {
			return {
				article: {
					params: [],
					total: 0
				},
				pageParams: {
					pageNum: 1,
					pageSize: 5
				},
				num: 0
			}
		},
		methods: {
			getItem(item){
				console.log(item,'item');
			},
			getList(data, flag = true) {
				if (flag) {
					getMyComment(data).then(res => {
						this.article.total = res.data.total
						this.article.params = this.article.params.concat(res.data.blogList)
					})
				} else {
					getMyComment(data).then(res => {
						this.article.total = res.data.total
						this.article.params = res.data.blogList
					})
				}

			},
			handleGet(val) {
				this.num = val;
			}

		}
	}
</script>

<style lang="scss">
	.content{
		margin-top: -70rpx;
	}
		.empty_container {
			display: flex;
			justify-content: center;
			align-items: center;
			height: 60vh;

			.u-empty {
				height: 60vh;
			}
		}
</style>